// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   InputStreaming.java

package canvas;

import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.Canvas;

// Referenced classes of package mquran:
//            QuranCanvas

public class InputStreaming extends InputStream
{

    public InputStreaming(InputStream is, int length, QuranCanvas canvas)
    {
        this.is = is;
        this.length = length;
        offset = 0;
        mark = 0;
        buffer = new byte[length];
        this.canvas = canvas;
        canvas.bar_width = length;
    }

    public int read()
        throws IOException
    {
        if(cur_offset >= length)
            return -1;
        if(cur_offset == offset)
        {
            int i = is.read();
            buffer[cur_offset++] = (byte)i;
            offset = cur_offset;
            if(offset % 128 == 1)
            {
                canvas.bar_progress += 128;
                canvas.paint_flag |= 2;
                canvas.repaint();
            }
            return i;
        } else
        {
            return buffer[cur_offset++] & 0xff;
        }
    }

    public synchronized void mark(int idx)
    {
        mark = cur_offset;
    }

    public synchronized void reset()
        throws IOException
    {
        cur_offset = mark;
    }

    public void close()
        throws IOException
    {
        is.close();
        canvas.bar_width = canvas.bar_progress = 0;
        canvas.paint_flag |= 2;
        canvas.repaint();
    }

    public int available()
        throws IOException
    {
        return length - cur_offset;
    }

    private InputStream is;
    private int length;
    private int offset;
    private int cur_offset;
    private int mark;
    private byte buffer[];
    private QuranCanvas canvas;
}
